﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PigLatinTranslator
{
    class PigLatinToEnglishTranslator : Translator
    {
        //Rule for Translating Piglatin to English
        //Grabs all the characters until the -
        //Then the other Argument picks up the words including the - to the end
        const string PigLatinToEnglishRule = @"(^[\w']*){1}|(\G-[\w']*(?=ay))";
        
        public override string translateWord(string Word)
        {
            //Pig Latin to English translator
            //Takes a word, then removes the pig latin extension
            MatchCollection WordParts = Regex.Matches(Word, PigLatinToEnglishRule, RegexOptions.IgnoreCase);
            if (WordParts.Count == 2)
                Word = WordParts[1].ToString().Substring(1) + WordParts[0].ToString();
            else //this is just for saftey
                Word = WordParts[0].ToString();
            return Word.ToLower();
        }

    }
}
